package com.app.megaprosoft.DB;

import java.sql.*;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class ArGroupMain {
	
	 ResultSet rs = null;
	 
	 SQLiteDBClass myDb;
	 SQLiteDatabase db;
	 Context context;
	 private static final String TABLE_ArGroupMain = "_ArGroupMain";
	 
	public ResultSet selectArGroupMain(String StrArGroupMainDesc) throws Exception {
		Connect con = new Connect(); 
		String StrSql   = "SELECT	 [OID]," +
									"[LastModified]," +
									"[ModifyDate]," +
									"[ModifyTime]," +
									"[ModifiedBy]," +
									"[UserModify]," +
									"[CreatedDate]," +
									"[CreateDate]," +
									"[CreateTime]," +
									"[CreatedBy]," +
									"[UserCreate]," +
									"[IsActive]," +
									"[IsDeleted]," + 
									
									"[ArGroupMainCode],"+
									"[ArGroupMainDesc],"+
									"[ArGroupMainDiscount] "+
									
						  "FROM		 [dbo].[udfArGroupMain] () " +
						  
						  "WHERE	 [IsDeleted]='0' ";   
			     	
		if (!StrArGroupMainDesc.equals("")) {
            StrSql += "AND [ArGroupMainDesc] LIKE '%" + StrArGroupMainDesc + "%'";
        }
    	
		return con.selectData(StrSql);
	 }
	
//	 public void closeConnecttion() throws Exception {
//    	 if (conn != null) {
//             conn.close();
//         }
//	 }
	 
	 
	public void DEFINE_ArGroupMain() {
			rs = null;
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();
			
		try {
			rs = selectArGroupMain("");
			while (rs.next()) {
				ContentValues Val = new ContentValues();
				Val.put("ArGroupMainOID", rs.getString("OID"));
				Val.put("ArGroupMainCode", rs.getString("ArGroupMainCode"));
				Val.put("ArGroupMainDesc", rs.getString("ArGroupMainDesc"));
				Val.put("ArGroupMainDiscount", rs.getString("ArGroupMainDiscount"));
				db.insert(TABLE_ArGroupMain, null, Val);
			}
			rs.close();
		} catch (Exception e) {
			Log.d("TABLE_ArGroupMain", "Create Table not Successfully.");
		}
		Log.d("TABLE_ArGroupMain", "Create Table Successfully.");
		db.close();
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}
	
	public String[][] SelectAll_ArGroupMain(String OID) throws Exception {
		// TODO Auto-generated method stub
		try {
			String arrData[][] = null;
			
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();
			
			String strSQL = "SELECT  ArGroupMainOID As _id , * FROM "
					+ TABLE_ArGroupMain ;
			if (!OID.equals("")) {
				strSQL += " WHERE [ArGroupMainOID] LIKE '" + OID + "' ";
			}
			Cursor cursor = db.rawQuery(strSQL, null);
			if (cursor != null) {
				if (cursor.moveToFirst()) {
					arrData = new String[cursor.getCount()][cursor
							.getColumnCount()];
					int i = 0;
					do {
						arrData[i][0] = cursor.getString(1);
						arrData[i][1] = cursor.getString(2);
						arrData[i][2] = cursor.getString(3);
						arrData[i][3] = cursor.getString(4);
						i++;
					} while (cursor.moveToNext());
				}
			}
			cursor.close();
			return arrData;
		} catch (Exception e) {
			return null;
		}
	}
	
	
}
